﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TheLocal.Common;

namespace TheLocal.ViewModel
{
    public sealed class ViewModelLocator
    {
        private LazyLoad<HomePageViewModel> homePageViewModel;
        private LazyLoad<CategoryPageViewModel> categoryPageViewModel;
        private LazyLoad<CountryListViewModel> countryListViewModel;
        private LazyLoad<CategoryListViewModel> categoryListViewModel;
        private LazyLoad<NewsListViewModel> newsListViewModel;
        private LazyLoad<NewsPageViewModel> newsPageViewModel;

        public ViewModelLocator()
        {
            InitializeViewModels();
        }

        public CountryListViewModel CountryListViewModel
        {
            get
            {
                return this.countryListViewModel.Value;
            }
        }

        public CategoryListViewModel CategoryListViewModel
        {
            get
            {
                return this.categoryListViewModel.Value;
            }
        }

        public NewsListViewModel NewsListViewModel
        {
            get
            {
                return this.newsListViewModel.Value;
            }
        }

        public NewsPageViewModel NewsPageViewModel
        {
            get
            {
                return this.newsPageViewModel.Value;
            }
        }

        public HomePageViewModel HomePageViewModel
        {
            get
            {
                return this.homePageViewModel.Value;
            }
        }

        public CategoryPageViewModel CategoryPageViewModel
        {
            get
            {
                return this.categoryPageViewModel.Value;
            }
        }

        private void InitializeViewModels()
        {
            this.countryListViewModel = new LazyLoad<CountryListViewModel>(() =>
                new CountryListViewModel());

            this.categoryListViewModel = new LazyLoad<CategoryListViewModel>(() =>
                new CategoryListViewModel());

            this.homePageViewModel = new LazyLoad<HomePageViewModel>(() =>
                new HomePageViewModel(this.CountryListViewModel));

            this.categoryPageViewModel = new LazyLoad<CategoryPageViewModel>(() =>
                new CategoryPageViewModel(this.CategoryListViewModel));

            this.newsListViewModel = new LazyLoad<NewsListViewModel>(() =>
                new NewsListViewModel());

            this.newsPageViewModel = new LazyLoad<NewsPageViewModel>(() =>
                new NewsPageViewModel(this.NewsListViewModel, this.CountryListViewModel.SelectedCountry, this.CategoryListViewModel.SelectedCategory));
        }
    }
}
